cmake_minimum_required(VERSION 2.8.12.2)

project(gooit)

set(PROJ_SRC_DIR "${PROJECT_SOURCE_DIR}")

set(RUNTIME_OUTPUT_DIRECTORY ${PROJ_SRC_DIR})

include_directories(${PROJ_SRC_DIR})

file(GLOB INCS "${PROJ_SRC_DIR}/*.h")
# generate a list of files that match the cpp source file with Globbing expressions and -
# store it into the variable SRCS 
file(GLOB SRCS "${PROJ_SRC_DIR}/*.cpp")
# display the source files recursively
foreach(file ${INCS} ${SRCS})
    message("   ${file}")
endforeach(file)

add_executable(${PROJECT_NAME} ${INCS} ${SRCS})

if(WIN32)
    add_definitions(-D_CRT_SECURE_NO_WARNINGS)
elseif(UNIX)
    set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
    set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2 -Wall")
else()
    message(SEND_ERROR ">>>> Current operation system platform not supported yet!")
endif()

# set install directory
set(_DEFAULT_INCLUDE_INSTALL_DIR include)
set(INCLUDE_INSTALL_DIR "${_DEFAULT_INCLUDE_INSTALL_DIR}" CACHE PATH "Include installation directory")
if(NOT IS_ABSOLUTE "${INCLUDE_INSTALL_DIR}")
    set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR}")
endif()

set(_DEFAULT_BINARY_INSTALL_DIR bin)
set(BINARY_INSTALL_DIR "${_DEFAULT_BINARY_INSTALL_DIR}" CACHE PATH "Binary installation directory")
if(NOT IS_ABSOLUTE "${_DEFAULT_BINARY_INSTALL_DIR}")
    set(BINARY_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${BINARY_INSTALL_DIR}")
endif()

set(_DEFAULT_LIBRARY_INSTALL_DIR lib)
if(EXISTS "${CMAKE_INSTALL_PREFIX}/lib32/" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
    set(_DEFAULT_LIBRARY_INSTALL_DIR lib32)
elseif(EXISTS "${CMAKE_INSTALL_PREFIX}/lib64/" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
    set(_DEFAULT_LIBRARY_INSTALL_DIR lib64)
endif()
set(LIBRARY_INSTALL_DIR "${_DEFAULT_LIBRARY_INSTALL_DIR}" CACHE PATH "Library installation directory")
if(NOT IS_ABSOLUTE "${LIBRARY_INSTALL_DIR}")
    set(LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIBRARY_INSTALL_DIR}")
endif()

message(STATUS "Install main directory: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "Binary installation directory: ${BINARY_INSTALL_DIR}")
message(STATUS "Include installation directory: ${INCLUDE_INSTALL_DIR}")
message(STATUS "Library installation directory: ${LIBRARY_INSTALL_DIR}")
message(STATUS "Executable name: ${PROJECT_NAME}${CMAKE_EXECUTABLE_SUFFIX}")

#install(FILES ${PROJECT_BINARY_DIR}/config.h DESTINATION ${INCLUDE_INSTALL_DIR})
#install(TARGETS ${PROJECT_NAME} 
#        RUNTIME DESTINATION ${BINARY_INSTALL_DIR} 
#        LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR} 
#        ARCHIVE DESTINATION ${LIBRARY_INSTALL_DIR}/static)
